package net.muhu.channel.service.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.muhu.channel.service.MusiverseServiceInMemory;
import net.muhu.channel.service.MusiverseServiceInMemoryImpl;
import net.muhu.domain.Location;
import net.muhu.domain.Musiverse;
import net.muhu.domain.Planet;
import net.muhu.musiverse.MusiverseService;
import net.muhu.util.MuhuDataFactory;

import org.junit.Before;
import org.junit.Test;

public class MusiverseInteractionTestCase {

	private static final String MUSIVERSE_ID = "test-musiverse";

	private MusiverseService cut;

	// TODO rewrite as behavior driven test
	// Given the Musiverse "TestMusiverse" without any location
	// When i add the planet "Earth"
	// Then the "TestMusiverse" has one planet with an id "Earth"

	@Before
	public void setup() {
		Musiverse musiverse = MuhuDataFactory.createMusiverse(MUSIVERSE_ID);
		musiverse.setName(MusiverseInteractionTestCase.class.getName());

		MusiverseServiceInMemory memory = new MusiverseServiceInMemoryImpl();
		memory.setMusiverse(musiverse);

		cut = memory;
	}

	@Test
	public void addPlanet() throws Exception {

		String planetId = "Earth";
		cut.addLocation(new Planet().withId(planetId));

		Musiverse actual = cut.getMusiverse(MUSIVERSE_ID);
		assertEquals(1, actual.getLocation().size());

		Location actualPlanet = actual.getLocation().get(0);
		assertTrue(actualPlanet instanceof Planet);
		assertEquals(planetId, actualPlanet.getId());
	}

}
